package com.easyedu.selection.dao;

import com.easyedu.core.entity.po.StudentSelect;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author lmr
 **/
@Mapper
public interface CourseSelectionDao {


    /**
     * 功能描述:新增学生选课</br>
     * 数据表：student_select(插入), student(查询) open_course(查询)
     *
     * @param studentNumber 1 学号
     * @param courseNumber  2 课程代号
     * @return : java.lang.Integer
     **/
    @Insert("insert into student_select(student_number, student_name, open_courses_id, course_code, course_number, " +
            "course_name,course_nature, credit, usual_score_ratio,experiment_score_ratio, exam_score_ratio, " +
            "create_time, update_time) SELECT s.student_number,s.name,o.open_courses_id,o.course_code,o" +
            ".course_number,o.course_name,o.course_nature,o.credit,usual_score_ratio,experiment_score_ratio," +
            "exam_score_ratio,now(),now() from student s,open_course o where s.student_number = #{studentNumber} AND " +
            "o.course_number = #{courseNumber}")
    Integer setStudentCourse(Long studentNumber, String courseNumber);

    /**
     * 功能描述:查询学生是否选择某课程
     *
     * @param studentNumber 1 学号
     * @param courseNumber  2 课程代号
     * @return : java.util.List<com.easyedu.api.entity.DO.StudentSelect>
     **/
    @Select("select * from student_select where student_number = #{studentNumber} AND course_number = #{courseNumber}")
    List<StudentSelect> getByStudentNumberAndCourseNumber(Long studentNumber, String courseNumber);

    /**
     * 功能描述:删除学生所选择的课程
     *
     * @param studentNumber 1 学号
     * @param courseNumber  2 课程代号
     * @return : java.lang.Integer
     **/
    @Delete("delete from student_select where student_number = #{studentNumber} AND course_number = #{courseNumber} ")
    Integer deleteByStudentNumberAndCourseNumber(Long studentNumber, String courseNumber);
}
